<template>
  <div id="releaseNeeds">
    <div id="rNmain">
      <div id="rNheader">发布你的需求，让二手货卖家更方便地找到你</div>
      <div id="blank">
        需求介绍
        <textarea
          name="need"
          id=""
          cols="30"
          rows="10"
          v-model="needDetail"
          placeholder="我想要一本二手vue.js教程QAQ"
        >
        </textarea>
        <i class="el-button" @click="submitNeed">上传需求</i>
      </div>
    </div>
  </div>
</template>

<script>
import need from "../components/need.vue";
import { postNeed } from "../network/product.js";

export default {
  name: "releaseNeeds",
  data() {
    return {
      needDetail: "",
    };
  },
  methods: {
    submitNeed() {
      if (this.needDetail.length == 0) {
        this.$message({
          message: "请填写具体需求！",
          type: "warning",
        });
        return;
      }
      console.log(this.needDetail);
      var date = new Date();
      var year = date.getFullYear(); //存储年
      var month = date.getMonth() + 1; //存储月份
      var day = date.getDate(); //存储日期
      var time = year + "." + month + "." + day;
      console.log(time);
      postNeed(this.needDetail, time).then((res) => {
        console.log(res);
        if (res.data.res == 1) {
          this.$message({
            message: "发布成功！",
            type: "success",
          });
          this.$router.push({
            path: "/",
          });
        }
      });
      // .catch(err=>{
      //     this.$message.error("Error");
      // })
    },
  },
  components: {
    need,
  },
};
</script>

<style scoped>
#rNmain {
  background-color: #fff;
}

#rNheader {
  padding: 20px;
  border-bottom: 1px solid #000;
}

#blank {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 20px;
  height: 320px;
}

#blank textarea {
  outline: none;
  padding: 10px;
  font: 16px "Microsoft Yahei";
}

#blank i {
  margin-left: 900px;
  height: 40px;
  font-style: normal;
  font-weight: bold;
}

.el-button {
  background-color: rgb(255, 0, 54);
  color: #fff;
}
</style>